/**
 * Created by Eoly on 2017/3/27.
 * Call http://palerock.cn
 */
app.controller("test", function ($http, $scope) {

    $scope.provinceList = [];
    $scope.province = {};

    $scope.cityList = [];
    $scope.city = {};

    $scope.countyList = [];
    $scope.county = {};


    $scope.getCity = function (type) {

        var pid = 0;

        switch (type) {
            case 'province':
                break;
            case 'city':
                $scope.countyList = [];
                $scope.county = {};
                if ($scope.province == null || $scope.province.id == null) return;
                pid = $scope.province.id;
                break;
            case 'county':
                if ($scope.city == null || $scope.city.id == null) return;
                pid = $scope.city.id;
                break;
            default:
                return;
        }

        var url = app.netPath + '/show-china';
        var param = {};
        param.pid = pid;

        $http({
            method: 'get',
            url: url,
            params: param
        }).then(
            function (result) {
                if (!result.data.error) {
                    console.log(result);
                    $scope[type + 'List'] = result.data.dataList;
                } else {
                    if (result.data.error == 55) {
                        return;
                    }
                    $.alert("错误代码:" + result.data.error + "," + result.data.mes)
                }

            },
            function (res) {
                alert("网路有问题")
            }
        )
    };

    $scope.$watch('province', function () {
        $scope.getCity('city');
    });

    $scope.$watch('city', function () {
        $scope.getCity('county');
    });


    $scope.getLocation = function () {
        

        setInterval(function () {
        	var p = app.addressInfo;
            if (p) {
                $.alert(
                    '经度：' + p.coords.longitude + ' ' +
                    '纬度：' + p.coords.latitude + ' ' +
                    '海拔：' + p.coords.altitudeAccuracy + ' ' +
                    '精确度：' + p.coords.accuracy + ' ' +
                    '详细信息：' + p.addresses + ' '
                )
            }
        }, 2000)


    }

});